#!/bin/sh

# install access-control-bridge
git clone git@codeup.aliyun.com:65e7d678db165442182db3d8/beeplus/access-control-bridge.git
cd access-control-bridge
npm install

# install pm2
npm install -g pm2
pm2 install pm2-logrotate

# set config
echo BRIDGE_PROJECT_ID=${BRIDGE_PROJECT_ID} >> .env
echo BRIDGE_PORT=${BRIDGE_PORT} >> .env
echo BRIDGE_MODE=${BRIDGE_MODE} >> .env
echo BRIDGE_DB_HOST=${BRIDGE_DB_HOST} >> .env
echo BRIDGE_DB_USER=${BRIDGE_DB_USER} >> .env
echo BRIDGE_DB_PASSWORD=${BRIDGE_DB_PASSWORD} >> .env
echo BRIDGE_DB_DATABASE=${BRIDGE_DB_DATABASE} >> .env

# build server
npm run build-server

# start server
pm2 start dist/server/main.js
pm2 start dist/script/auto-update.js

# save
pm2 save